/**
 *  @file SQLiteTransaction.h
 */
#ifndef _SQLITETRANSACTION_H_
#define _SQLITETRANSACTION_H_

#include "../../common/BaseObject.h"

namespace cppflib
{

namespace database
{

namespace sqlite
{

class SQLiteDatabase;


/**
 *  To explicitly start a transaction
 *
 *  Use this class as follows:
 *
 *  SQLiteTransaction *pTran = new SQLiteTransaction(pDB);
 *  try {
 *     pTran->Begin();
 *     ...
 *     ... // update DB here
 *     ...
 *     pTran->SetCommitOK(); // set commit OK
 *  }
 *  catch(BaseException &e) {
 * 
 *  }
 *
 *  pTran->End();  // call End finally
 */
class _DLLAPI SQLiteTransaction : public BaseObject
{
private:
    bool isCommitOK;
    SQLiteDatabase * pDB;
private:
    SQLiteTransaction(void);
public:
    typedef enum
    {
       DEFERRED,
       IMMEDIATE,
       EXCLUSIVE,
    } locktype_t;

    explicit SQLiteTransaction(SQLiteDatabase * pDB);
    virtual ~SQLiteTransaction(void);

    bool Begin();
    bool Begin(locktype_t lockType);
    void SetCommitOK();
    bool End();
    void Close();
};

} // end of namespace sqlite

} // end of namespace database

} // end of namespace cppflib


#endif
